package com.IO.stream;

import java.io.*;
import java.util.ArrayList;

/***
 * @ClassName: objectStream
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 22:36 2022/2/6
 * @version : V1.0
 */
public class objectStream {
    public static void main(String[] args) throws IOException {

        output();
        input();
    }

    //序列化
    public static void output() throws IOException {
        FileOutputStream fio = new FileOutputStream("d:\\st.bin");
        ObjectOutputStream oos = new ObjectOutputStream(fio);
        // 2. 序列化（写入操作）
        Student zs = new Student(1, "张三");
        Student ls = new Student(1, "李四");
        ArrayList<Student> students = new ArrayList<>();
        students.add(zs);
        students.add(ls);
        oos.writeObject(students);
        oos.close();
    }

    //序列化
    public static void input(){
        try {
            FileInputStream fio = new FileInputStream("d:\\st.bin");
            ObjectInputStream ois = new ObjectInputStream(fio);
            ArrayList<Student> students = (ArrayList<Student>) ois.readObject();
            ois.close();
            System.out.println(students);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
